<?php

namespace App\Http\Controllers\Api;

use App\Http\ApiResponse;
use App\Http\Controllers\BaseController;

class MiniAppController extends BaseController
{
    protected $pageSize = 15;
    protected $pageNum = 1;

    /**
     * http请求的返回控制对象
     * @var ApiResponse \App\Http\ApiResponse
     */
    protected $apiResponse;

    public function __construct()
    {
        $request = request();
        $this->apiResponse = new ApiResponse($this);
        $this->pageNum = intval($request->input('page_num', 1));
        $this->pageSize = intval($request->get("limit", 16));
    }

    public function pre_attack($data)
    {
        if (is_array($data)) {
            foreach ($data as $key => $val) {
                $data [$key] = trim($val);
                $data [$key] = strip_tags($val);
                $data [$key] = htmlspecialchars($val);
                // $data [$key] = $this->my_addslashes($val);
            }
        } else {
            $data = trim($data);  //清理空格
            $data = strip_tags($data);   //过滤html标签
            $data = htmlspecialchars($data);   //将字符内容转化为html实体

            // $data = $this->my_addslashes($data);  //防止SQL注入
        }
        return $data;
    }

    function my_addslashes($var)
    {
        if (!get_magic_quotes_gpc()) {

            if (is_array($var)) {
                foreach ($var as $key => $val) {
                    $var [$key] = my_addslashes($val);
                }
            } else {
                $var = addslashes($var);
            }
        }
        return $var;
    }
}
